#include <setjmp.h>
#include <stdio.h>
#include <stdlib.h>


/* Very simple main program that demonstrates the different return values
 * for setjmp() */
int main()
{
    //buffer for setjmp()/longjmp()
    //stores registers
    jmp_buf env;
    int i;

    //call setjmp
    //registers are stored to env, this is the point to that we go back
    i = setjmp(env);
    //setjmp() returns 0 in its first call, if we go back with longjmp()
    //the value is different
    printf("i = %d\n", i);

    //we exit after the first longjmp()
    if( i!= 0) exit(0);

    //we jump to the point that we saved with the first setjmp call
    //the return value is 2 (must be different from 0)
    longjmp(env, 2);
    
    //we cannot see it as we exit our program before
    printf("Can you see this line=\n");
}

